/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bitoon.basketdudes.jpa;

/**
 * @author paco
 */

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name = "participe", schema = "basket")
@NamedQueries({
    @NamedQuery(name = "Participe.findByTemporadaEquipo",
        query = "SELECT p FROM Participe p WHERE p.participePK.temporadaId = :temporada_id and p.participePK.equipo.id = :equipo_id"),
    @NamedQuery(name = "Participe.Clasificacion",
        query = "SELECT p FROM Participe p WHERE p.participePK.temporadaId = :temporada_id order by puntos desc,favor-contra desc,favor desc,p.participePK.equipo.id asc"),
    @NamedQuery(name = "Participe.findByEquipoIdTemporadaId",
        query = "SELECT p FROM Participe p WHERE p.participePK.equipo.id = :equipoId "
        + "AND p.participePK.temporadaId = :temporadaId"),
    @NamedQuery(name = "Participe.findByTemporadaIdEstado",
        query = "SELECT p FROM Participe p WHERE p.participePK.temporadaId = :temporadaId "
        + "AND estado = :estado"),
    @NamedQuery(name = "Participe.findByTemporadaId",
        query = "SELECT p FROM Participe p WHERE p.participePK.temporadaId = :temporada_id "),
    @NamedQuery(name = "Participe.findById",
        query = "SELECT p FROM Participe p WHERE p.participePK.temporadaId = :temporada_id and p.participePK.equipo.id = :equipo_id ")

})


public class Participe implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ParticipePK participePK;
    @Column(name = "estado")
    private Short estado;
    @Column(name = "ganados")
    private Short ganados;
    @Column(name = "perdidos")
    private Short perdidos;
    @Column(name = "favor")
    private Integer favor;
    @Column(name = "contra")
    private Integer contra;
    @Column(name = "puntos")
    private Integer puntos;



    @JoinColumn(name = "temporada_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false,fetch=FetchType.LAZY)
    private Temporada temporada;

    public Participe() {
    }

    public Participe(ParticipePK participePK) {
        this.participePK = participePK;
    }

    public Participe(int temporadaId, int equipoId) {
        this.participePK = new ParticipePK(temporadaId, equipoId);
    }

    public ParticipePK getParticipePK() {
        return participePK;
    }

    public void setParticipePK(ParticipePK participePK) {
        this.participePK = participePK;
    }

    public Short getEstado() {
        return estado;
    }

    public void setEstado(Short estado) {
        this.estado = estado;
    }

    public Short getGanados() {
        return ganados;
    }

    public void setGanados(Short ganados) {
        this.ganados = ganados;
    }

    public Short getPerdidos() {
        return perdidos;
    }

    public void setPerdidos(Short perdidos) {
        this.perdidos = perdidos;
    }

    public Integer getFavor() {
        return favor;
    }

    public void setFavor(Integer favor) {
        this.favor = favor;
    }

    public Integer getContra() {
        return contra;
    }

    public void setContra(Integer contra) {
        this.contra = contra;
    }

    public Integer getPuntos() {
        return puntos;
    }

    public void setPuntos(Integer valor) {
        this.puntos = valor;
    }

    public Temporada getTemporada() {
        return temporada;
    }

    public void setTemporada(Temporada temporada) {
        this.temporada = temporada;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (participePK != null ? participePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Participe)) {
            return false;
        }
        Participe other = (Participe) object;
        if ((this.participePK == null && other.participePK != null) || (this.participePK != null && !this.participePK.equals(other.participePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bitoon.basketdudes.jpa.Participe[participePK=" + participePK + "]";
    }

}
